package com.example.qq_demo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.material.bottomnavigation.BottomNavigationView;

public class Index_Activity extends AppCompatActivity {
private BottomNavigationView nav_btn;
    private Fragment fr_xx,fr_lxr,fr_dt,fr_sz;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        initView();
    }

    private void initView() {
        nav_btn=findViewById(R.id.nav);


        nav_btn.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                switch (menuItem.getItemId())
                {
                    case R.id.mav_information:
                        FragmentManager  fm = getSupportFragmentManager();
                        //创建事务
                        FragmentTransaction transaction = fm.beginTransaction();
                        //调用碎片，替换主页的fragment
                        transaction.replace(R.id.frame,new fragment_xx());
                        //进行替换
                        transaction.commit();
                        return true;
                    case R.id.mav_contactPerson:
                        FragmentManager  fm2 = getSupportFragmentManager();
                        //创建事务
                        FragmentTransaction transaction2 = fm2.beginTransaction();
                        //调用碎片，替换主页的fragment
                        transaction2.replace(R.id.frame,new fragment_lxr());
                        //进行替换
                        transaction2.commit();
                        return true;
                    case R.id.mav_dynamic:
                        FragmentManager  fm3 = getSupportFragmentManager();
                        //创建事务
                        FragmentTransaction transaction3 = fm3.beginTransaction();
                        //调用碎片，替换主页的fragment
                        transaction3.replace(R.id.frame,new fragment_dt());
                        //进行替换
                        transaction3.commit();
                        return true;
                    case R.id.mav_setUp:
                        FragmentManager  fm4 = getSupportFragmentManager();
                        //创建事务
                        FragmentTransaction transaction4 = fm4.beginTransaction();
                        //调用碎片，替换主页的fragment
                        transaction4.replace(R.id.frame,new fragment_sz());
                        //进行替换
                        transaction4.commit();
                        return true;
                }
                return false;
            }
        });
    }
}
